package com.weijianhuawen.wjblog.web.service.impl;

import com.weijianhuawen.wjblog.common.domain.dos.BlogSettingsDo;
import com.weijianhuawen.wjblog.common.domain.mapper.BlogSettingsMapper;
import com.weijianhuawen.wjblog.common.enums.ResponseCodeEnum;
import com.weijianhuawen.wjblog.common.exception.BizException;
import com.weijianhuawen.wjblog.common.utils.Response;
import com.weijianhuawen.wjblog.web.convert.BlogSettingsConvert;
import com.weijianhuawen.wjblog.web.mode.vo.blogsettings.FindBlogSettingsDetailRspVo;
import com.weijianhuawen.wjblog.web.service.BlogSettingsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-10-28 23:23
 */

@Service
@Slf4j
public class BlogSettingsServiceImpl implements BlogSettingsService {
    @Resource
    private BlogSettingsMapper blogSettingsMapper;
    @Override
    public Response finBlogSettingsDetail() {
        // 查询id为1的博客设置信息
        BlogSettingsDo blogSettingsDo = blogSettingsMapper.selectById(1L);
        if (Objects.isNull(blogSettingsDo)) {
            // 数据库缺少管理员博客信息
            log.warn("【博客设置服务】 数据库数据缺失，博客设置数据");
            throw new BizException(ResponseCodeEnum.NOT_EXIST_ADMIN_BLOG_SETTINGS);
        }
        // 将do 转 vo
        FindBlogSettingsDetailRspVo vo = BlogSettingsConvert.INSTANCE.convertDoToVo(blogSettingsDo);
        return Response.success(vo);
    }
}
